#include "progressBar.h" 
#include <unistd.h>

typedef void (*callback_t)(int);  // 函数指针类型 

void downLoad(callback_t cb)
{
    int total = 1000;
    int cur = 0;
    while(cur <= total) 
    {
        usleep(50000);  // 模拟下载速度
        int rate = cur * 100 / total;
        cb(rate);   //通过回调，更新进度
        cur += 10;
    }
    printf("\n");
}

int main()
{
    printf("donwnload 1: \n");
    downLoad(processbar);
    printf("donwnload 2: \n");
    downLoad(processbar);
    printf("donwnload 3: \n");
    downLoad(processbar);
    printf("donwnload 4: \n");
    downLoad(processbar);


    // v1版本
    //processbar(10000);
    return 0;
}
